﻿using B.S.Traceability.Domain;
using B.S.Traceability.Error;
using B.S.Traceability.Infrastructure.Interface;
using B.S.Traceability.Read.API.Application.Commends.Slaughter;
using MediatR;

namespace B.S.Traceability.Read.API.Application.CommendHandlers.Slaughter
{
    public class GetSlaughterCommendHandlers : IRequestHandler<GetSlaughterCommends, APIResult<List<Slaughters>>>
    {


        private readonly IBaseRepository<Slaughters> SlaughtersRepository;

        public GetSlaughterCommendHandlers(IBaseRepository<Slaughters> slaughtersRepository)
        {
            SlaughtersRepository = slaughtersRepository;
        }


        /// <summary>
        /// 根据批次号查询屠宰信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<List<Slaughters>>> Handle(GetSlaughterCommends request, CancellationToken cancellationToken)
        {
            APIResult<List<Slaughters>> result=new APIResult<List<Slaughters>>();
          

            result.Code = APIEnum.查询成功;
            result.Msg = "查询成功";
            var list = SlaughtersRepository.GetAll().Where(p => p.BatchId == request.BatchId && p.IsDel == false);
            result.data = list.ToList();
            return await Task.FromResult(result);
        }
    }
}
